﻿using BaseData.API.Write.Applications.AppointmentIng.AppointCommand;
using BaseData.Domain.Appointment;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;

namespace BaseData.API.Write.Applications.AppointmentIng.AppointCommandHandler
{
    /// <summary>
    /// 预约修改状态
    /// </summary>
    public class AppoinStateCommandHandler : IRequestHandler<AppoinStateCommand, ApiResult<int>>
    {
        IBaseRepository<Appointments> appointRep;

        public AppoinStateCommandHandler(IBaseRepository<Appointments> appointRep)
        {
            this.appointRep = appointRep;
        }

        public async Task<ApiResult<int>> Handle(AppoinStateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = ApiEnum.修改成功;
            result.Message = ApiEnum.修改成功.ToString();

            var list = await appointRep.GetById(request.AppointmentId);

            list.MedicalState = true;

            await appointRep.UpdateAsync(list);
            result.Data = 1;

            return await Task.FromResult(result);
        }
    }
}
